package ar.edu.itba.it.cg.grupo01.impl.shape;

import static com.google.common.base.Preconditions.checkNotNull;

import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

import ar.edu.itba.it.cg.grupo01.impl.Precision;

public class MathPlane {
	
	public Point3d point;
	public Vector3d normal;

	
	public MathPlane(Point3d aPoint, Vector3d normal) {
		checkNotNull(aPoint, "The plane's specified point cannot be null");
		checkNotNull(normal, "The plane's normal cannot be null");
		
		this.point = (Point3d) aPoint.clone();
		this.normal = (Vector3d) normal.clone();
		this.normal.normalize();
	}
	
	public boolean contains(Point3d anotherPoint) {
		
		Vector3d aux = new Vector3d(normal);
		double belong = Math.abs(aux.dot(new Vector3d(anotherPoint))
				+ this.getDistanceToOrigin());
		if (Math.abs(belong) < Precision.EPSILON) {
			return true;
		}
		return false;
	}
	
	public double getDistanceToOrigin() {
		Vector3d auxVec = new Vector3d(normal);
		return (-auxVec.dot(new Vector3d(point)));
	}

}
